/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package orderProcessingProcess.dataStorage;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;

import orderProcessingProcess.model.Address;
import orderProcessingProcess.model.Customer;
import orderProcessingProcess.model.Item;
import orderProcessingProcess.model.Payment_Preference;
import orderProcessingProcess.server.OrderManagementService;
import orderProcessingProcess.util.AIC_log;

/**
 *
 * @author dreni
 */
public class TestDataEntry {

    public TestDataEntry(){
        initTestData();
    }


    private void initTestData(){
        Address addr1 = new Address();
        addr1.setId("001");
        addr1.setStreet("1st Avenue");
        addr1.setCity("New Your");
        addr1.setHouse(1);
        addr1.setDoor(1);
        addr1.setZip_code("10000");

        Customer customer1 = new Customer();
        customer1.setId("00001");
        customer1.setName("John Foo");
        customer1.setAddress(addr1);
        customer1.setPaymentPreference(Payment_Preference.Credit_Card);

        Address addr2 = new Address();
        addr2.setId("001");
        addr2.setStreet("2nd Avenue");
        addr2.setCity("New Jersy");
        addr2.setHouse(2);
        addr2.setDoor(2);
        addr2.setZip_code("20000");

        Customer customer2 = new Customer();
        customer2.setId("00002");
        customer2.setName("Boby Bar");
        customer2.setAddress(addr1);
        customer2.setPaymentPreference(Payment_Preference.Bank_Transfer);


        Address addr3 = new Address();
        addr3.setId("003");
        addr3.setStreet("3rd Avenue");
        addr3.setCity("New Orleans");
        addr3.setHouse(3);
        addr3.setDoor(3);
        addr3.setZip_code("30000");

        Customer customer3 = new Customer();
        customer3.setId("00003");
        customer3.setName("Lisa Foo");
        customer3.setAddress(addr3);
        customer3.setPaymentPreference(Payment_Preference.Bank_Transfer);

        Address addr4 = new Address();
        addr4.setId("004");
        addr4.setStreet("4th Avenue");
        addr4.setCity("New Orleans");
        addr4.setHouse(4);
        addr4.setDoor(4);
        addr4.setZip_code("40000");

        Customer customer4 = new Customer();
        customer4.setId("00004");
        customer4.setName("Mary Bar");
        customer4.setAddress(addr4);
        customer4.setPaymentPreference(Payment_Preference.Credit_Card);
        
        DataBackend db = DataBackend.getInstance();
        db.addCustomer(customer1);
        db.addCustomer(customer2);
        db.addCustomer(customer3);
        db.addCustomer(customer4);
        
        List<Item> items = new ArrayList<Item>();
    	
        items.add(new Item(1200, "1", new BigDecimal(12.90),null));
    	items.add(new Item(300, "2", new BigDecimal(2.90),null));
    	items.add(new Item(500, "3", new BigDecimal(3.90),null));
    	items.add(new Item(200, "4", new BigDecimal(3.90),null));
    	items.add(new Item(500, "5", new BigDecimal(3.90),null));
    	items.add(new Item(0, "999", new BigDecimal(3.90),null));
    	
    	JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    	factory.getInInterceptors().add(new LoggingInInterceptor());
    	factory.getOutInterceptors().add(new LoggingOutInterceptor());
    	factory.setServiceClass(OrderManagementService.class);
    	factory.setAddress("http://localhost:8083/orderservice");
    	OrderManagementService client = (OrderManagementService) factory.create();

    	client.insert_test_data(items);
        AIC_log.print("TestDataEntry", "Added Item (product) with ID = 1");
        AIC_log.print("TestDataEntry", "Added Item (product) with ID = 2");
        AIC_log.print("TestDataEntry", "Added Item (product) with ID = 3");
        AIC_log.print("TestDataEntry", "Added Item (product) with ID = 4");
        AIC_log.print("TestDataEntry", "Added Item (product) with ID = 5");

        AIC_log.print("TestDataEntry", "Done with testdata entry.");
    }
}
